package com.example.userlogon.controller;
import com.example.userlogon.entity.Goods;
import com.example.userlogon.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.events.Event;

//Controller -- 返回是视图； 使用restController，返回字符串对象
@RestController
@RequestMapping("/api")
public class apiController {

    @Autowired
    GoodsService goodsService;

    /**
     * 删除商品的方法
     * @param id
     * @return
     */
    @RequestMapping("/goodsDelete")
    public Integer goodsDelete(@RequestParam Integer id){
        System.out.println("接收到的参数id值是:"+id);
        Goods goods=new Goods();
        goods.setId(id);
//        1.调用service的删除方法
        if(goodsService.delete(goods)==1){
            return 1;
        }else{
            return 0;
        }
    }
    //处理更新操作
    @RequestMapping("/goodsUpdateProcess")
    public Integer goodsUpdateProcess(@RequestParam String id,@RequestParam String name,@RequestParam String price,
                                  @RequestParam String quantity,@RequestParam String category,
                                  @RequestParam String supplier){
//      组装一个goods实体对象
        Goods goods=new Goods(Integer.valueOf(id),name,Float.valueOf(price),Integer.valueOf(quantity),category,supplier,"0");
        //调用service里的update方法
        if(goodsService.update(goods)==1){
            return 1;
        }else{
            return 0;
        }
}}
